using System.Collections.Generic;
using BikeSystem.DAL;
using BikeSystem.Models;

namespace BikeSystem.BLL
{
    public class RentalManager
    {
        RentalService renterService = new RentalService();
        BikeService bikeService = new BikeService();

        public CommonMessage Rental(Rental rental)
        {
            CommonMessage message = new CommonMessage();

            Bike bike = bikeService.GetBikeByBikeNo(rental.BikeNo);
            if (null != bike)
            {
                if (bike.Status)
                {
                    renterService.Rental(rental);
                    message.Message = "Rented Success.";
                    message.Success = true;
                }
                else
                {

                    message.Message = "This Bike Not Available";
                    message.Success = false;
                }
               
            }
            else
            {
                message.Message = "Not Found This Bike";
                message.Success = false;
            }

            return message;
        }

        public IList<Rental> GetAllRentals()
        {
            return renterService.GetAllRentals();
        }

        public CommonMessage UpdateRental(Rental renterBike)
        {

            CommonMessage message = new CommonMessage();
            int iret = renterService.UpdateRental(renterBike);
            if (iret == 0)
            {
                message.Success = true;
                message.Message = "Payment success";
            }
            else
            {
                message.Success = false;
                message.Message = "Payment unsuccess, rental information not found";
            }
            return message;
        }

        public Rental GetRental(string RentNo)
        {
            return renterService.GetRental(RentNo);
        }

    }
}
